#include <iostream>
#include <map>
#include <stack>

using namespace std;

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */

class MinStack
{
private:
    map<int, int> valueCounter;
    stack<int> valueStack;

public:
    MinStack()
    {
    }

    void push(int val)
    {
        valueStack.push(val);
        valueCounter[val]++;
    }

    void pop()
    {
        int top = valueStack.top();
        valueStack.pop();
        valueCounter[top]--;
        if (valueCounter[top] == 0)
            valueCounter.erase(top);
    }

    int top()
    {
        return valueStack.top();
    }

    int getMin()
    {
        return valueCounter.begin()->first;
    }
};

int main()
{
    MinStack minStack;
    minStack.push(-2);
    minStack.push(0);
    minStack.push(-3);
    cout << minStack.getMin() << endl;
    minStack.pop();
    cout << minStack.top() << endl;
    cout << minStack.getMin() << endl;
    return 0;
}